﻿using log4net;
using ServerControl.Dal;
using ServerControl.Model;
using ServerControl.WebManage.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServerControl.Utils;

namespace ServerControl.WebManage.Controllers.Admin
{
    [RoutePrefix("admin/log")]
    [Auth(AllowRole = Model.Enum.Role.AdminOrUser)]
    public class LogController : BaseController
    {
        private ILog logger = LogManager.GetLogger("LogController");

        [Route("index")]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [Route("list-page")]
        public JsonResult ListPage(int page = 1, int limit = 20, string account = "")
        {
            try
            {
                int records = 0;
                var logs = LogDal.Select(ref records, page, limit, CurrentUser.UserName, account);
                return new JsonNetResult { Data = new SuccessResult<List<Log>> { Data = logs, Count = records, Msg = "" } };
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return new JsonNetResult { Data = new FailResult { Msg = "请求异常" } };
        }
    }
}